//
//  FZHomeToolBar.swift
//  MyWeiBo
//
//  Created by fangzhengwei on 2017/3/30.
//  Copyright © 2017年 fangzhengwei. All rights reserved.
//

import UIKit

class FZHomeToolBar: UIView {
    
    var retweetBtn : UIButton?
    var commentBtn : UIButton?
    var unlikeBtn : UIButton?
    
    var statusToolBarModel : FZStatusViewModel?{
        
        didSet {
            
            let reportCount = statusToolBarModel?.statusModel?.reposts_count
            let commonCount = statusToolBarModel?.statusModel?.comments_count
            let  attitudesCount = statusToolBarModel?.statusModel?.attitudes_count
            
            if let reCount = reportCount ,reCount > 0 {
                
                retweetBtn?.setTitle("\(reCount)", for: .normal)
            }
            
            if let comCount = commonCount ,comCount > 0 {
                
                commentBtn?.setTitle("\(comCount)", for: .normal)
            }

            if let attCount = attitudesCount ,attCount > 0 {
                
                unlikeBtn?.setTitle("\(attCount)", for: .normal)
            }
   
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
       backgroundColor = UIColor.white
    }
    
    func setupUI() {
        
       retweetBtn = createBtn(imgName: "timeline_icon_retweet", title: "转发")
       commentBtn = createBtn(imgName: "timeline_icon_comment", title: "评论")
       unlikeBtn = createBtn(imgName: "timeline_icon_unlike", title: "赞")
      
     retweetBtn?.snp.makeConstraints { (make) in
       make.top.left.bottom.equalTo(self)
       make.width.equalTo(commentBtn!)
     }
     
     commentBtn?.snp.makeConstraints { (make) in
        make.top.bottom.equalTo(self)
        make.left.equalTo((retweetBtn?.snp.right)!)
        make.width.equalTo(unlikeBtn!)
    }
        
      unlikeBtn?.snp.makeConstraints { (make) in
         make.top.bottom.right.equalTo(self)
         make.left.equalTo((commentBtn?.snp.right)!)
      }
        
      addLineAction()
    }
    
    func addLineAction() {
        
        let line1 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        let line2 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        addSubview(line1)
        addSubview(line2)
        
        line1.snp.makeConstraints { (make) in
            
            make.top.bottom.equalTo(self)
            make.left.equalTo(self).offset(screenWidth/3)
        }
        
        line2.snp.makeConstraints { (make) in
            
            make.top.bottom.equalTo(self)
            make.right.equalTo(self).offset(-screenWidth/3)
        }
    }
    
    func createBtn(imgName : String, title : String) -> UIButton {
        let btn = UIButton()
        btn.setImage(UIImage(named :imgName), for: .normal)
        btn.setTitle(title, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        addSubview(btn)
        return btn
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
